using System;
using Csla;
using Csla.Serialization;

namespace Northwind.BusinessObjects
{
    [Serializable]
    public class ProductInfo : ReadOnlyBase<ProductInfo>
    {
        #region Business Methods

        public static readonly PropertyInfo<int> ProductIdProperty = RegisterProperty<int>(c => c.ProductId);
        public int ProductId
        {
            get { return GetProperty(ProductIdProperty); }
            private set { LoadProperty(ProductIdProperty, value); }
        }

        public static readonly PropertyInfo<string> ProductNameProperty = RegisterProperty<string>(c => c.ProductName);
        public string ProductName
        {
            get { return GetProperty(ProductNameProperty); }
            private set { LoadProperty(ProductNameProperty, value); }
        }

        public static readonly PropertyInfo<Nullable<int>> SupplierIdProperty = RegisterProperty<Nullable<int>>(c => c.SupplierId);
        public Nullable<int> SupplierId
        {
            get { return GetProperty(SupplierIdProperty); }
            private set { LoadProperty(SupplierIdProperty, value); }
        }

        public static readonly PropertyInfo<Nullable<int>> CategoryIdProperty = RegisterProperty<Nullable<int>>(c => c.CategoryId);
        public Nullable<int> CategoryId
        {
            get { return GetProperty(CategoryIdProperty); }
            private set { LoadProperty(CategoryIdProperty, value); }
        }

        public static readonly PropertyInfo<string> QuantityPerUnitProperty = RegisterProperty<string>(c => c.QuantityPerUnit);
        public string QuantityPerUnit
        {
            get { return GetProperty(QuantityPerUnitProperty); }
            private set { LoadProperty(QuantityPerUnitProperty, value); }
        }

        public static readonly PropertyInfo<Nullable<decimal>> UnitPriceProperty = RegisterProperty<Nullable<decimal>>(c => c.UnitPrice);
        public Nullable<decimal> UnitPrice
        {
            get { return GetProperty(UnitPriceProperty); }
            private set { LoadProperty(UnitPriceProperty, value); }
        }

        public static readonly PropertyInfo<Nullable<int>> UnitsInStockProperty = RegisterProperty<Nullable<int>>(c => c.UnitsInStock);
        public Nullable<int> UnitsInStock
        {
            get { return GetProperty(UnitsInStockProperty); }
            private set { LoadProperty(UnitsInStockProperty, value); }
        }

        public static readonly PropertyInfo<Nullable<int>> UnitsOnOrderProperty = RegisterProperty<Nullable<int>>(c => c.UnitsOnOrder);
        public Nullable<int> UnitsOnOrder
        {
            get { return GetProperty(UnitsOnOrderProperty); }
            private set { LoadProperty(UnitsOnOrderProperty, value); }
        }

        public static readonly PropertyInfo<Nullable<int>> ReorderLevelProperty = RegisterProperty<Nullable<int>>(c => c.ReorderLevel);
        public Nullable<int> ReorderLevel
        {
            get { return GetProperty(ReorderLevelProperty); }
            private set { LoadProperty(ReorderLevelProperty, value); }
        }

        public static readonly PropertyInfo<bool> DiscontinuedProperty = RegisterProperty<bool>(c => c.Discontinued);
        public bool Discontinued
        {
            get { return GetProperty(DiscontinuedProperty); }
            private set { LoadProperty(DiscontinuedProperty, value); }
        }
        #endregion

        #region Data Access

#if !SILVERLIGHT
        private void Child_Fetch(Northwind.DataAccess.ProductDto item)
        {
          ProductId = item.ProductId;
          ProductName = item.ProductName;
          SupplierId = item.SupplierId;
          CategoryId = item.CategoryId;
          QuantityPerUnit = item.QuantityPerUnit;
          UnitPrice = item.UnitPrice;
          UnitsInStock = item.UnitsInStock;
          UnitsOnOrder = item.UnitsOnOrder;
          ReorderLevel = item.ReorderLevel;
          Discontinued = item.Discontinued;
        }
#endif
        #endregion
    }
}
